<template>
  <!--修改密码-->
  <div class="login">
    <p class="banner"><img src="../../assets/banner.png" alt="" width="100%"></p>
    <wv-group>
      <wv-input placeholder="请输入原密码" type="password" v-model="oldpassword"></wv-input>
      <wv-input placeholder="请输入新密码" :type="type" class="pwd" v-model="passwold">
        <img :src="src" alt="" slot="ft" @click="change" width="30" >
      </wv-input>
      <wv-input placeholder="请确认新密码" :type="type1" class="pwd" v-model="newpasswold">
        <img :src="src1" alt="" slot="ft" @click="change1" width="30">
      </wv-input>
    </wv-group>
    <wv-button type="primary" @click="goUpdatePw()">确定</wv-button>
  </div>
</template>

<script type="text/ecmascript-6">
  import {resetOldpw} from '../../../test/unit/http'
  import {Toast} from 'we-vue'
  export default {
    name: 'xiugaipwd',
    props: {},
    data() {
      return {
        type: 'password',
        src: require('../../assets/bieye.png'),
        type1: 'password',
        src1: require('../../assets/bieye.png'),
        oldpassword: '',
        passwold: '',
        newpasswold: ''
      };
    },
    methods: {
      change(){
        this.type = this.type == 'password' ? 'text' : 'password';
        this.src = this.src == require('../../assets/eye.png') ? require('../../assets/bieye.png') : require('../../assets/eye.png')
      },
      change1(){
        this.type1 = this.type1 == 'password' ? 'text' : 'password';
        this.src1 = this.src1 == require('../../assets/eye.png') ? require('../../assets/bieye.png') : require('../../assets/eye.png')
      },
      checkForm () {
        var msg = {};
        if (this.$myUtils.isNull(this.oldpassword)) {
          msg['result'] = false;
          msg['info'] = '请输入原密码';
          return msg;
        }
        if (this.$myUtils.isNull(this.passwold)) {
          msg['result'] = false;
          msg['info'] = '请输入新密码';
          return msg;
        }
        if (this.$myUtils.isNull(this.newpasswold)) {
          msg['result'] = false;
          msg['info'] = '请输入确认密码';
          return msg;
        }
        if (this.passwold != this.newpasswold) {
          msg['result'] = false;
          msg['info'] = '两次密码输入不一致';
          return msg;
        }
        var result=this.$myUtils.checkPwStrong(this.newpasswold);
        if(!result){
          Toast.text("密码过于简单");
          return;
        }
        msg['result'] = true;
        msg['info'] = '校验成功';
        return msg;
      },
      goUpdatePw(){
        var checkResult = this.checkForm();
        if (!checkResult.result) {
          Toast.text(checkResult.info);
          return;
        }
        let params = {oldpassword: this.oldpassword, password: this.passwold};
        resetOldpw(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.$router.back(-1)
          }else{
            Toast.text(res.info)
          }
        })
      }
    },
    created() {

    },
    computed: {

    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: center;
    img {
      position: absolute;
      right: 10px;
      top: 10px
    }
    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: 100%;
        border-radius: 8px;
        margin-top: 25px;
        background-color: #f98e3c;
      }
    }
  }

  .banner img {
    object-fit: cover;
  }

  .weui-btn_primary {
    background-color: #f98e3c;
    margin-top: 30px;
  }

  button.weui-btn {
    width: 94%;
    margin-top: 30px;
  }

  .weui-btn_primary a {
    color: #fff;
  }

  .weui-cell:before {
    right: 15px;
  }
</style>
